import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userInfo: {},
		hasLogin: false,
		Thone: '',
	},
	mutations: {
		login(state, provider) { //改变登录状态  
			state.hasLogin = true;
			state.userInfo.token = provider.token;
			store.commit("setuserInfo",provider);
			uni.setStorage({ //将用户信息保存在本地  
				key: 'userInfo',
				data: provider
			})

		},
		setuserInfo(state, userInfo) {
			state.userInfo = userInfo;
		},
		logout(state) { //退出登录  
			state.hasLogin = false
			state.userInfo = {}
			uni.removeStorage({
				key: 'userInfo'
			})
		}
	}
})

export default store
